int teamCount = 30;
String[] teamNames;
String[] teamCodes;
HashMap teamIndices;
SalaryList salaries;

void setupTeams(){
  String[] lines = loadStrings("teams.tsv");
  
  teamCount = lines.length;
  teamCodes = new String[teamCount];
  teamNames = new String[teamCount];
  teamIndices = new HashMap();
  
  for(int i=0;i<teamCount; i++){
    String[] pieces = split(lines[i], TAB);
    teamCodes[i] =pieces[0];
    teamNames[i] =pieces[1];
    teamIndices.put(teamCodes[i], new Integer(i));
  }
}

int teamIndex(String teamCode){
  Integer index = (Integer) teamIndices.get(teamCode);
  return index.intValue();
}

void setup(){
    
  println("In progress");
}

void setupSalaries(){
  String[] lines = loadStrings("salaries.tsv");
  salaries = new SalaryList(lines);
}
/*
void parseWinLoss(String[] lines){
  // pattern to match any {(word or digit) + (.anything)}
  Pattern p = Pattern.compile("\\s+([\\w\\d]+):\\s'(.*)',?");

  String teamCode = "";
  int wins = 0;
  int losses = 0;
  String teamName = "";

  for (int i=0;i<lines.length; i++){
    Matcher m = p.matcher(lines[i]);

    if(m.matches()){
      String attr = m.group(1);
      String value = m.group(2);

      if(attr.equals("code")){
        teamCode = value;
      } 
      else if(attr.equals("w")){
        wins = int(value);
      } 
      else if(attr.equals("l")){
        losses = int(value);
      } 
      else if (attr.equals("league_sensitive_team_name")){
        teamName = value;
      }
    } 
    else {
      if(lines[i].startsWith("}")){
        // This is the end of the group; print the values.
        standings.println(teamCode + TAB + wins + TAB +losses);
        teams.println(teamCode + TAB + teamName);
      }
    }
  }
}


/**
import java.util.regex.*;

// Salary Data from http://content.usatoday.com/sports/baseball/salaries/totalpayroll.aspx?year=2007

PrintWriter standings;
PrintWriter teams;
String[] tms;

void setup(){
  String[] lines = loadStrings("teams.tsv");
  tms = new String[lines.length];
  for(int i = 0; i < lines.length; i++){
    String[] pieces =split(lines[i], TAB);
    // The tree-digit code for the team is in the first column
    tms[i] = pieces[0];
  }

  grabLogos("small", "http://mlb.mlb.com/mlb/images/team_logos/logo_", "_small.gif");
  getTeamData();
}
void grabLogos(String folder,String prefix, String suffix){
  String extension = suffix.substring(suffix.length() -4);
  for (int i =0; i<tms.length; i++){
    String filename = folder + "/" + tms[i]+extension;
    String url = prefix+tms[i]+suffix;
    println("Downloading "+url);
    saveStream(filename,url);
  }
}

void getTeamData(){
  String base = "http://mlb.mlb.com/components/game/year_2007/month_09/day_06/";
  standings = createWriter("standings.tsv");
  teams = createWriter("teams.tsv");

  parseWinLoss(loadStrings(base + "standings_rs_ale.js"));
  parseWinLoss(loadStrings(base + "standings_rs_alw.js"));
  parseWinLoss(loadStrings(base + "standings_rs_alc.js"));

  parseWinLoss(loadStrings(base + "standings_rs_nle.js"));
  parseWinLoss(loadStrings(base + "standings_rs_nlw.js"));
  parseWinLoss(loadStrings(base + "standings_rs_alc.js"));

  // Finish writing and close each file
  standings.flush();
  standings.close();
  teams.flush();
  teams.close();

  println("Done");
}

*/
